package org.raymond.iworks.study.orders.controller;

import org.raymond.iworks.apis.common.Result;
import org.raymond.iworks.study.orders.service.IOrderService;
import org.raymond.iworks.study.orders.service.ISecKillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private ISecKillService iSecKillService;

    @PostMapping("/init")
    public Result init() throws Exception {
        iSecKillService.initData();
        return Result.success();
    }

    @PostMapping("/secKill/{userId}/{productId}/{num}")
    public Result secKill(@PathVariable("userId") Long userId,
                          @PathVariable("productId") Long productId,
                          @PathVariable("num") Integer num) throws Exception {
        iSecKillService.secKill(userId, productId, num);
        return Result.success();
    }

    @PostMapping("/cancel/{userId}/{productId}")
    public Result cacnel(@PathVariable("userId") Long userId,
                         @PathVariable("productId") Long productId){
        iSecKillService.cancel(userId, productId);
        return Result.success();
    }
}
